import { NgModule } from '@angular/core';
import { Routes, RouterModule, } from '@angular/router';
// import { NoPreloading } from '@angular/router';
// import { PreloadAllModules } from '@angular/router';
import { LoadMarkedPreloadStrategy } from './core/implements/preloadStrategy.loadMarked';
import { AuthGuard } from './core/services/auth.guards';

/**
 * 路由配置:
 *
 * 备注:和LoadMarkedPreloadStrategy配合,在路由上设置 preload: true 使对应模块在首页加载完毕后加载
 * 该预加载策略主要考虑高频模块的加载不要延迟到路由跳转
 */
export const routes: Routes = [
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    {
        path: 'task', loadChildren: 'app/task/task.module#TaskModule',
        canActivate: [AuthGuard], data: { preload: true }
    },
    {
        path: 'demo', loadChildren: 'app/demo/demo.module#DemoModule',
        canActivate: [AuthGuard], data: { preload: true }
    },
    { path: '**', redirectTo: 'notfound' }
];

const routeConfig = {
    // 'useHash': true, //HTML5 OR HASH
    'preloadingStrategy': LoadMarkedPreloadStrategy
    // 'preloadingStrategy': NoPreloading
};

@NgModule({
    imports: [RouterModule.forRoot(routes, routeConfig)],
    providers: [LoadMarkedPreloadStrategy],
    exports: [RouterModule]
})
export class AppRoutingModule { }